package io.renren.socket.client;

import java.net.Socket;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import io.renren.common.utils.R;

/**
 * 测试是否 连接成功
 * 
 * @author lfy.xys
 * @date 2018年6月20日
 *
 */
public class TestConnClient   {
	
	private static Logger logger = LoggerFactory.getLogger(TestConnClient.class);

	public String ip;
	public int port;
	
	public TestConnClient(String ip, int port) {
		this.ip = ip;
		this.port = port;
	}

	/**
	 * 测试是否连接成功，使用原始socket，不需要使用nio
	 * 
	 * @author lfy.xys
	 * @date 2018年6月20日
	 *
	 * @return
	 */
	@SuppressWarnings("resource")
	public R testConn() {
		boolean flag = true;
		String msg = "";
		try {
			new Socket(ip, port);
			msg = "连接成功";
		} catch (Exception e) {
			flag = false;
			msg = "连接失败";
		}
		logger.info(msg);
		return R.ok().put("result", flag).put("msg", msg);
	}

 

}
